package tt.dz.biz.service.paymentgateway;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.paymentgateway.PaymentWateWayDAOImp;
import tt.dz.vo.PayGateVO;

@Service("paymentGateWayService")
public class PaymentGateWayService
{
  @Resource(name="paymentWateWayDAO")
  private PaymentWateWayDAOImp paymentWateWayDAO;
  
  public List<Map<String, Object>> getPayChannelSel()
    throws Exception
  {
    return this.paymentWateWayDAO.getPayChannelSel();
  }
  
  public List<Map<String, Object>> getMerchantSel()
    throws Exception
  {
    return this.paymentWateWayDAO.getMerchantSel();
  }
  
  public List<PayGateVO> getPayGateList(Map<String, ?> paramMap)
    throws Exception
  {
    return this.paymentWateWayDAO.getPayGateList(paramMap);
  }
  
  public PayGateVO getMsPayGateVO(String merchantCode, String channelCode)
    throws Exception
  {
    PayGateVO payGateVO = new PayGateVO();
    payGateVO.setMerchantCode(merchantCode);
    payGateVO.setChannelCode(channelCode);
    return this.paymentWateWayDAO.getPayGateByID(payGateVO);
  }
  
  public int savePayGate(PayGateVO payGateVO)
    throws Exception
  {
    if (payGateVO != null)
    {
      if (this.paymentWateWayDAO.checkPayGateExists(payGateVO) == 1) {
        return this.paymentWateWayDAO.updatePayGate(payGateVO);
      }
      return this.paymentWateWayDAO.insertPayGate(payGateVO);
    }
    return -1;
  }
  
  public boolean checkPayGateExists(String merchantCode, String channelCode)
    throws Exception
  {
    PayGateVO payGateVO = new PayGateVO();
    payGateVO.setMerchantCode(merchantCode);
    payGateVO.setChannelCode(channelCode);
    return this.paymentWateWayDAO.checkPayGateExists(payGateVO) == 1;
  }
}
